﻿using System;
using System.IO;
using System.Text;

namespace CodeGeneration.Util
{
    public class TemplateUtil
    {
        public static void RenderStringToFile(string content,string file)
        {
            var dir = Path.GetDirectoryName(file);
            if (string.IsNullOrEmpty(dir)&&!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            CreateFile(file, content);
        }
        private static void CreateFile(string fileName, string contents)
        {
            if (File.Exists(fileName) && File.ReadAllText(fileName) == contents)
            {
                return;
            }

            File.WriteAllText(fileName, contents,Encoding.UTF8);
        }
    }
}